﻿using Main.Repository;
using System.Linq.Expressions;

namespace Main.EFCore
{
    public class BaseServer<T> : IBaseServer<T> where T : class, new()
    {
        private IRepository<T> _Respository;

        public BaseServer(IRepository<T> repository)
        {
            _Respository = repository;
        }
        public bool Add(T t)
        {
            return _Respository.Add(t);
        }

        public bool AddRange(IEnumerable<T> t)
        {
            return (_Respository.AddRange(t));
        }

        public bool Delete(T t)
        {
            return _Respository.Delete(t);
        }

        public bool DeleteRange(IEnumerable<T> t)
        {
            return _Respository.DeleteRange(t);
        }

        public T Find(dynamic Id)
        {
            return _Respository.Find(Id);
        }


        public bool Update(T t)
        {
            return _Respository.Update(t);
        }

        public bool UpdateRange(IEnumerable<T> t)
        {
            return _Respository.UpdateRange(t);
        }


        public bool UpdateWhere(Expression<Func<T, bool>> WhereLambda, Func<T, T> UpdateLambda)
        {
            return _Respository.UpdateWhere(WhereLambda, UpdateLambda);
        }


        public IQueryable<T> QueryAll(Expression<Func<T, bool>>? where)
        {
            return _Respository.QueryAll(where);
        }

        public IQueryable<T> QueryAll(params Expression<Func<T, bool>>[] wheres)
        {
            return _Respository.QueryAll(wheres);
        }

        public IQueryable<T> QueryAll<type>(Expression<Func<T, type>> order, bool isAsc = true, Expression<Func<T, bool>>? where = null)
        {
            return _Respository.QueryAll(order, isAsc, where);
        }

        public IQueryable<T> QueryAll<type>(out int total, int skip, int take, Expression<Func<T, type>> order, bool isAsc = true, Expression<Func<T, bool>>? where = null)
        {
            return _Respository.QueryAll(out total, skip, take, order, isAsc, where);
        }

        public Task<bool> AddAsync(T t)
        {
            return _Respository.AddAsync(t);
        }

        public Task<bool> AddRangeAsync(IEnumerable<T> t)
        {
            return _Respository.AddRangeAsync(t);
        }

        public Task<bool> DeleteAsync(T t)
        {
            return _Respository.DeleteAsync(t); 
        }

        public Task<bool> DeleteRangeAsync(IEnumerable<T> t)
        {
            return _Respository.DeleteRangeAsync(t);
        }

        public Task<bool> UpdateAsync(T t)
        {
            return _Respository.UpdateAsync(t); 
        }

        public Task<bool> UpdateRangeAsync(IEnumerable<T> t)
        {
            return _Respository.UpdateRangeAsync(t);    
        }

        public Task<bool> UpdateWhereAsync(Expression<Func<T, bool>> WhereLambda, Func<T, T> UpdateLambda)
        {
            return _Respository.UpdateWhereAsync(WhereLambda, UpdateLambda);    
        }
    }
}
